<script setup>
import { defineProps, computed } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const props = defineProps({
  object: {
    type: Object,
    required: true
  },
  type: {
    type: String,
    required: true
  }
})

function handleClick() {
  if (props.type === '课件') {
    console.log(props.object.article.id)
    return router.push(`/article-detail?id=${props.object.article.id}`)
  }
  if (props.type === '需求') {
    return router.push(`/question-detail?id=${props.object.question.id}`)
  }
}
// 用计算属性再处理
const data = computed(() => {
  console.log(props);
  return props.type === '课件' ? props.object.article : props.object.question
})
</script>
<template>
  <div class="container" @click="handleClick">
    <div class="title-container">
      <div class="title">
        <span class="type-badge" :class="dynamicClasses"> {{ type }} </span>
        {{ data.title }}
      </div>
    </div>
    <div class="details">
      <div class="detail-item">
        <div class="label">发布人</div>
        <div class="value">{{ object.user.nickName }}</div>
      </div>
      <div class="detail-item">
        <div class="label">部门</div>
        <div class="value">{{ object.user.department }}</div>
      </div>
      <div class="detail-item">
        <div class="label">类型</div>
        <div class="value">{{ data.type }}</div>
      </div>
    </div>
    <div class="footer">
      <div class="time">发布时间： {{ data.date }}</div>
      <!-- <div class="status" v-if="type === '课件'">{{ info.status }}</div> -->
    </div>
  </div>
</template>
<style scoped>
/* 容器样式 */
.container {
  background-color: #ffffff;
  padding: 0.75rem; /* 12px */
  border-radius: 0.5rem; /* 8px */
  display: flex;
  flex-direction: column;
  cursor: pointer;
}

.container:hover {
  box-shadow:
    0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* 标题容器样式 */
.title-container {
  margin-left: 0.25rem; /* 4px */
  margin-right: 0.25rem; /* 4px */
  margin-top: 0.25rem; /* 4px */
  margin-bottom: 0.25rem; /* 4px */
}

/* 标题样式 */
.title {
  font-size: 1.25rem; /* 20px */
  font-weight: bold;
  line-height: 1.625; /* 26px for 16px base size */
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* number of lines to show */
  -webkit-box-orient: vertical;
}

.type-badge {
  color: #ffffff;
  background-color: #a0aec0; /* gray-500 in Tailwind CSS */
  border-bottom-right-radius: 0.125rem; /* 2px */
  font-size: 0.875rem; /* 14px */
  padding-left: 0.375rem; /* 6px */
  padding-right: 0.375rem; /* 6px */
  padding-top: 0.25rem; /* 4px */
  padding-bottom: 0.25rem; /* 4px */
  margin-right: 0.25rem; /* 4px */
  vertical-align: 0.125rem; /* 2px */
  min-width: max-content;
  max-width: max-content;
}

/* 细节部分样式 */
.details {
  background-color: #f7fafc; /* gray-100 in Tailwind CSS */
  border-radius: 0.5rem; /* 8px */
  margin-top: 0.75rem; /* 12px */
  margin-left: 0.25rem; /* 4px */
  margin-right: 0.25rem; /* 4px */
  padding: 0.25rem; /* 4px */
  display: flex;
  justify-content: space-around;
}

.detail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 33.333333%; /* 1/3 of the container's width */
  text-align: center;
}

.label {
  color: #a0aec0; /* gray-500 in Tailwind CSS */
  margin: 0.25rem; /* 4px */
}

.value {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-left: 0.75rem; /* 12px */
  padding-right: 0.75rem; /* 12px */
  margin: 0.25rem; /* 4px */
}

/* 底部信息样式 */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-left: 0.5rem; /* 8px */
  margin-right: 0.5rem; /* 8px */
  margin-top: 0.5rem; /* 8px */
}

.time {
  color: #cbd5e0; /* gray-400 in Tailwind CSS */
  margin-top: 0.625rem; /* 10px */
  margin-bottom: 0.625rem; /* 10px */
}
</style>
